package com.zhuxiang.test5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * 服务器类
 */
public class Server {

    public static void main(String[] args) {
        ServerSocket ss = null;
        Socket s = null;
        List<Socket> list = new ArrayList<>();

        try {
            ss = new ServerSocket(8888);
            BufferedReader br = null;
            PrintStream ps = null;
            while (true){
                System.out.println("...等待连接中...");
                s = ss.accept();
                //将连上的客户端放到list中
                list.add(s);
                System.out.println(s.getPort() + "已上线");
                //开启服务器线程
                new ServerThread(s,list).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
        }
    }
}
